package com.vm.activity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.Volley;
import com.vm.adapter.FragAdapter;
import com.vm.adapter.PresentAdapter;
import com.vm.commons.TabConst.ConValue;
import com.vm.fragment.ActiveFragment;
import com.vm.fragment.CategoryFragment;
import com.vm.fragment.IndexFragment;
import com.vm.fragment.MallFragment;
import com.vm.fragment.ManagerFragment;
import com.vm.fragment.NecessaryAppFragment;
import com.vm.fragment.NecessaryGameFragment;
import com.vm.model.Soft;
import com.vm.utils.JsonUtils;
import com.wwt.app.R;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TabHost.TabSpec;

/**
 * 
 * @ProjectName: [WeiMai]
 * @Author: [kent.wang]
 * @CreateDate: [2015年1月29日 下午5:13:56]
 * @Version: [v1.0]
 * 
 */
public class NecessaryActivity extends FragmentActivity {

	protected static final String TAG = "NecessaryActivity";

	RadioButton rbtn_game;
	RadioButton rbtn_app;
	ImageButton imgbtn_back;
	Button btn_search;

	private ViewPager vp;
	private FragAdapter adapter;
	List<Fragment> fragments;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.necessary);

		init();
		initChilds();

	}

	public void init() {
		rbtn_game = (RadioButton) findViewById(R.id.rbtn_game);
		rbtn_app = (RadioButton) findViewById(R.id.rbtn_app);
		imgbtn_back = (ImageButton) findViewById(R.id.imgbtn_back);
		btn_search = (Button) findViewById(R.id.btn_search);

		rbtn_game.setOnClickListener(rbtnClickListener);
		rbtn_app.setOnClickListener(rbtnClickListener);
		imgbtn_back.setOnClickListener(rbtnClickListener);
		btn_search.setOnClickListener(searchClickListener);
	}

	private void initChilds() {
		fragments = new ArrayList<Fragment>();
		fragments.add(new NecessaryAppFragment());
		fragments.add(new NecessaryGameFragment());
		vp = (ViewPager) findViewById(R.id.viewpager);
		adapter = new FragAdapter(getSupportFragmentManager(), fragments);
		vp.setAdapter(adapter);

		// 设置最大缓存数
		// 默认缓存2个页面,当出现第三个页面会删掉之前缓存中的一个.
		vp.setOffscreenPageLimit(2);
		vp.setCurrentItem(0);

		// fm = getSupportFragmentManager();// 获取fragment管理工具类
		// replace(new FoundFragment());
	}

	OnClickListener rbtnClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (v == rbtn_app) {
				vp.setCurrentItem(0);
			} else if (v == rbtn_game) {
				vp.setCurrentItem(1);
			} else if (v == imgbtn_back) {
				onBackPressed();
			}
		}
	};

	/**
	 * 手机自带返回按钮监听
	 */
	@Override
	public void onBackPressed() {
		super.onBackPressed();

	}

	/**
	 * 搜索按钮监听
	 */
	public OnClickListener searchClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(NecessaryActivity.this,
					SearchActivity.class);
			startActivity(intent);
		}
	};

}
